var Logs=function(){
	var grid;
	var fs,win;
	var pageSize = 30;
	var ds=new Ext.data.Store({
		proxy:new Ext.data.HttpProxy({url:'./?ctrl=logs&action=get'}),
		reader:new Ext.data.JsonReader({
			root: 'topics',
			totalProperty: 'totalCount',
			id: 'id',
			fields: ['id','member_id','url','ip','postDate']
		})
	});
	var grouprend=function(value ,metadata ,record ,rowIndex ,colIndex ,store ){
			return getLocTime(value);
		};
	var buildGrid = function(){
		grid = new Ext.grid.GridPanel({
			store:ds,
			columns:[
			new Ext.grid.RowNumberer({header :'ID',dataIndex:'id'}),
			{header:'管理员',width:50,sortable:true,dataIndex:'member_id',editor:new Ext.form.TextField()},
			{header:'提交地址',width:150,sortable:true,dataIndex:'url',editor:new Ext.form.TextField()},
			{header:'ip地址',width:50,sortable:true,dataIndex:'ip',editor:new Ext.form.TextField()},
			{header:'提交日期',width:100,sortable:true,dataIndex:'postDate',editor:new Ext.form.TextField(),renderer: grouprend}
			], bbar:new Ext.PagingToolbar({
				pageSize:pageSize,
				store:ds,
				displayInfo:true
			}),
			viewConfig:{
				forceFit:true
			},
			renderTo:'grid',
			height: 620,
			width:580,
			border:false
		});
		grid.on('cellclick',function(g,rowIndex,columnIndex,e){

			var lists=g.selModel.getSelections();
			var id=lists[0].id;
			//$.each( lists, function(i, obj){ids+=obj.id+",";});
			//alert(ids);

			var url="./?ctrl=logs&action=alllog&id="+id;
			var f_dom=Ext.get('alllog').dom;
			if(f_dom.src!=url){
				f_dom.src=url;
			}
		});
		grid.store.load();
	};
	var buildLayout = function(){
		var win;
		var subfrom;
		df = new Ext.form.DateField({
			format:'Y-m-d',
			value:new Date().format('Y-m')+'-01'
		});
		df.on('change',function(field,newValue,oldValue){
			grid.store.baseParams['df'] = df.getRawValue();
		});
		dt = new Ext.form.DateField({
			format:'Y-m-d',
			value:new Date().format('Y-m-d')
		});
		dt.on('change',function(field,newValue,oldValue){
			grid.store.baseParams['dt'] = dt.getRawValue();
		});
		toolbar = new Ext.Panel({
			border:false,
			tbar:[
			'日期从',df,
			'日期到',dt,
			{
				text:'查询',
				cls:'x-btn-text-icon',
				icon:RES_ROOT_PATH+'images/forward.gif',
				handler:function(){
					ds.load();
				}
			}]
		});
		//		var toolbar = new Ext.Panel({
		//			border:false,
		//			tbar:[{
		//				text:'删除',
		//				cls:'x-btn-text-icon',
		//				icon:RES_ROOT_PATH+'images/delete.gif',
		//				//enableToggle:true,
		//				//pressed:true,
		//				handler:function(){
		//					Ext.Msg.confirm('提示', '是否确认删除么？？？', function(btn){
		//						if (btn == 'yes'){
		//							var lists=grid.selModel.getSelections();
		//							var idss="";
		//							$.each( lists, function(i, obj){idss+=obj.id+",";});
		//							Ext.Ajax.request({
		//								url: './?ctrl=logs&action=delete',
		//								failure: function(response , options ){Ext.MessageBox.alert("信息","提交失败！");},
		//								success: function(response , options ){
		//									Ext.MessageBox.alert("信息","提交成功！");
		//									grid.store.reload();
		//								},
		//								headers: {
		//								'my-header': 'foo'
		//								},
		//								params: { ids: idss }
		//							});
		//						}
		//					},this);
		//				}
		//			},'-',{
		//				text:"全选",
		//				cls:"x-btn-text-icon",
		//				icon:RES_ROOT_PATH+'images/add.gif',
		//				handler:function(){
		//					grid.selModel.selectAll();
		//				}
		//			}]
		//		});

		var layout = new Ext.Viewport({
			layout:'border',
			defaults:{border:false},
			items:[{
				region:'north',
				title:'日志列表',
				height:52,
				items:toolbar
			},{
				region:'west',
				width:580,
				height: 200,
				split:true,
				autoScroll:true,
				items:grid
			},{
				region:'center',
				layout:'fit',
				title:'详情',
				items:new Ext.Panel({
					renderTo:"panl",
					html : Ext.isIE?'<iframe id="alllog" scrolling="no" frameborder="0" style="width:100%;height:100%;"></iframe>':'<iframe id="safe" scrolling="no" frameborder="0" style="width:100%;height:800px;"></iframe>'
				})
			}]
		});
	}
	return{
		init:function(){
			// Ext.state.Manager.setProvider(new Ext.state.SessionProvider({state: Ext.appState}));
			buildGrid();
			buildLayout();
		}
	}
}();
Ext.onReady(Logs.init,Logs);